home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / perl-5.003.tar.gz / perl-5.003.tar / perl-5.003 / x2p / handy.h < prev    next >
C/C++ Source or Header  |  1995-02-08  |  6KB  |  173 lines

  1. /*    handy.h
  2.  *
  3.  *    Copyright (c) 1991-1994, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #if !defined(__STDC__)
  11. #ifdef NULL
  12. #undef NULL
  13. #endif
  14. #ifndef I286
  15. #  define NULL 0
  16. #else
  17. #  define NULL 0L
  18. #endif
  19. #endif
  20.  
  21. #define Null(type) ((type)NULL)
  22. #define Nullch Null(char*)
  23. #define Nullfp Null(FILE*)
  24. #define Nullsv Null(SV*)
  25.  
  26. #ifdef UTS
  27. #define bool int
  28. #else
  29. #define bool char
  30. #endif
  31.  
  32. #ifdef TRUE
  33. #undef TRUE
  34. #endif
  35. #ifdef FALSE
  36. #undef FALSE
  37. #endif
  38. #define TRUE (1)
  39. #define FALSE (0)
  40.  
  41. typedef char        I8;
  42. typedef unsigned char    U8;
  43.  
  44. typedef short        I16;
  45. typedef unsigned short    U16;
  46.  
  47. #if BYTEORDER > 0x4321
  48.   typedef int        I32;
  49.   typedef unsigned int    U32;
  50. #else
  51.   typedef long        I32;
  52.   typedef unsigned long    U32;
  53. #endif
  54.  
  55. #define Ctl(ch) (ch & 037)
  56.  
  57. #define strNE(s1,s2) (strcmp(s1,s2))
  58. #define strEQ(s1,s2) (!strcmp(s1,s2))
  59. #define strLT(s1,s2) (strcmp(s1,s2) < 0)
  60. #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  61. #define strGT(s1,s2) (strcmp(s1,s2) > 0)
  62. #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  63. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  64. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  65.  
  66. #ifdef HAS_SETLOCALE  /* XXX Is there a better test for this? */
  67. #  ifndef CTYPE256
  68. #    define CTYPE256
  69. #  endif
  70. #endif
  71.  
  72. #ifdef USE_NEXT_CTYPE 
  73. #define isALNUM(c)   (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
  74. #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
  75. #define isALPHA(c)   NXIsAlpha((unsigned int)c)
  76. #define isSPACE(c)   NXIsSpace((unsigned int)c)
  77. #define isDIGIT(c)   NXIsDigit((unsigned int)c)
  78. #define isUPPER(c)   NXIsUpper((unsigned int)c)
  79. #define isLOWER(c)   NXIsLower((unsigned int)c)
  80. #define toUPPER(c)   NXToUpper((unsigned int)c)
  81. #define toLOWER(c)   NXToLower((unsigned int)c)
  82. #else /* USE_NEXT_CTYPE */
  83. #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
  84. #define isALNUM(c)   (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
  85. #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
  86. #define isALPHA(c)   isalpha((unsigned char)(c))
  87. #define isSPACE(c)   isspace((unsigned char)(c))
  88. #define isDIGIT(c)   isdigit((unsigned char)(c))
  89. #define isUPPER(c)   isupper((unsigned char)(c))
  90. #define isLOWER(c)   islower((unsigned char)(c))
  91. #define toUPPER(c)   toupper((unsigned char)(c))
  92. #define toLOWER(c)   tolower((unsigned char)(c))
  93. #else
  94. #define isALNUM(c)   (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
  95. #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
  96. #define isALPHA(c)   (isascii(c) && isalpha(c))
  97. #define isSPACE(c)   (isascii(c) && isspace(c))
  98. #define isDIGIT(c)   (isascii(c) && isdigit(c))
  99. #define isUPPER(c)   (isascii(c) && isupper(c))
  100. #define isLOWER(c)   (isascii(c) && islower(c))
  101. #define toUPPER(c)   toupper(c)
  102. #define toLOWER(c)   tolower(c)
  103. #endif
  104. #endif /* USE_NEXT_CTYPE */
  105.  
  106. /* Line numbers are unsigned, 16 bits. */
  107. typedef U16 line_t;
  108. #ifdef lint
  109. #define NOLINE ((line_t)0)
  110. #else
  111. #define NOLINE ((line_t) 65535)
  112. #endif
  113.  
  114. #ifndef lint
  115. #ifndef LEAKTEST
  116. #ifndef safemalloc
  117. Malloc_t safemalloc _((MEM_SIZE));
  118. Malloc_t saferealloc _((char *, MEM_SIZE));
  119. void safefree _((char *));
  120. #endif
  121. #ifndef MSDOS
  122. #define New(x,v,n,t)  (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  123. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  124. #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
  125.     memzero((char*)(v), (n) * sizeof(t))
  126. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  127. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  128. #else
  129. #define New(x,v,n,t)  (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
  130. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
  131. #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
  132.     memzero((char*)(v), (n) * sizeof(t))
  133. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  134. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  135. #endif /* MSDOS */
  136. #define Safefree(d) safefree((char*)d)
  137. #define NEWSV(x,len) newSV(len)
  138. #else /* LEAKTEST */
  139. char *safexmalloc();
  140. char *safexrealloc();
  141. void safexfree();
  142. #define New(x,v,n,t)  (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  143. #define Newc(x,v,n,t,c)  (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  144. #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
  145.     memzero((char*)(v), (n) * sizeof(t))
  146. #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  147. #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  148. #define Safefree(d) safexfree((char*)d)
  149. #define NEWSV(x,len) newSV(x,len)
  150. #define MAXXCOUNT 1200
  151. long xcount[MAXXCOUNT];
  152. long lastxcount[MAXXCOUNT];
  153. #endif /* LEAKTEST */
  154. #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
  155. #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
  156. #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
  157. #else /* lint */
  158. #define New(x,v,n,s) (v = Null(s *))
  159. #define Newc(x,v,n,s,c) (v = Null(s *))
  160. #define Newz(x,v,n,s) (v = Null(s *))
  161. #define Renew(v,n,s) (v = Null(s *))
  162. #define Move(s,d,n,t)
  163. #define Copy(s,d,n,t)
  164. #define Zero(d,n,t)
  165. #define Safefree(d) d = d
  166. #endif /* lint */
  167.  
  168. #ifdef USE_STRUCT_COPY
  169. #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
  170. #else
  171. #define StructCopy(s,d,t) Copy(s,d,1,t)
  172. #endif
  173.